// Database.cpp: implementation of the CDatabase class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"
#include "Database.h"
#include "FileLogging.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

CDatabase * CDatabase::_singleton = NULL;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDatabase::CDatabase()
{
	try {
		CRegister * reg = CRegister::GetInstance();

		con.CreateInstance(__uuidof(Connection));    
		//con->Open("Provider=SQLNCLI;Server=127.0.0.1;Database=EBAS;Uid=ebas;Pwd=ebas;", reg->get_User(), reg->get_Password(), -1);
    con->Open(GetConnectString(), reg->get_User(), reg->get_Password(), -1);
		con->AddRef();
	} catch (_com_error &e) {
		long l = (long)e.Error();
		char temp[16];
		ltoa(l, temp, 10);

		CFileLogging::WriteToFile(temp);
		CFileLogging::WriteToFile(e.ErrorMessage());
		CFileLogging::WriteToFile(e.Description());

		e.Description();
	}
}

CDatabase::~CDatabase()
{
	if (con)
		con->Release();
}
